/*
 * @ProjectName: flutter_common
 * @Package: 
 * @ClassName: user_identity.dart
 * @Description:
 * @User: Page.Su
 * @Date: 2020/8/31
 * @Time: 16:06
 * @UpdateDate: 2020/8/31 16:06
 */

import 'package:flutter/material.dart';
import 'package:flutter_su/common/app_color.dart';
import 'package:flutter_su/common/fun.dart';
import 'package:flutter_su/common/language_text.dart';
import 'package:flutter_su/enum/language_type.dart';
import 'package:flutter_su/provider/language_provider.dart';
import 'package:provider/provider.dart';

class UserIdentityPage extends StatefulWidget {
  final String type;
  final int index;

  const UserIdentityPage({Key key, @required this.type, this.index}) : super(key: key);

  @override
  _UserIdentityPageState createState() => _UserIdentityPageState();
}

class _UserIdentityPageState extends State<UserIdentityPage> {
  LanguageProvider _languageProvider; // app语言的状态管理

  List<String> _lists;

  final List<String> _userTypeListCh = ["项目方", "投资者", "投资中间人"];
  final List<String> _userTypeListEn = [
    "projectParty",
    "investors",
    "investmentMiddleman"
  ];

  final List<String> _userIdentityCh = ["个人", "公司"];
  final List<String> _userIdentityEn = ["personal", "company"];

  @override
  void initState() {
    _languageProvider = Provider.of<LanguageProvider>(context, listen: false);

    // 初始化List
    if (widget.type == "userType") {
      _lists = _languageProvider.getLanguageType == LanguageType.chinese
          ? _userTypeListCh
          : _userTypeListEn;
    } else {
      _lists = _languageProvider.getLanguageType == LanguageType.chinese
          ? _userIdentityCh
          : _userIdentityEn;
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: LanguageText.countryList,
        centerTitle: true,
        elevation: 0,
        backgroundColor: AppColor.MAIN_COLOR_BLUE,
      ),
      backgroundColor: AppColor.MAIN_COLOR_BLUE,
      body: _body(),
    );
  }

  Widget _body() {
    return Container(
      child: ListView.separated(
        itemCount: _lists.length,
        itemBuilder: (BuildContext context, int index) {
          return _item(_lists[index], index);
        },
        separatorBuilder: (context, index) {
          return Divider(
            indent: SFunCommon.width(75),
            endIndent: SFunCommon.width(75),
            color: AppColor.MAIN_COLOR_CYAN,
          );
        },
      ),
    );
  }

  Widget _item(String text, int index) {

    Color textColor = index == widget.index ? Colors.red : Colors.white;

    Widget textWidget = Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Text(
          text,
          style: SFunCommon.fontStyle(
            textColor,
            fontSize: 30,
          ),
        ),
      ],
    );

    return GestureDetector(
      onTap: () {
        String data = "$text/$index";
        Navigator.pop<String>(context, data);
      },
      child: Container(
        color: AppColor.TRANSPARENT,
        margin: EdgeInsets.only(
          left: SFunCommon.width(80),
        ),
        child: textWidget,
      ),
    );
  }
}
